package com.anbao.newanbao;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.TypeReference;
import com.anbao.action.ActivityManagerAction;
import com.anbao.dataBean.HistoryAlarmBean;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Toast;

public class QueryAlarmResultActivity extends Activity {
	private ImageView left_img;
	private ListView historyAlarmListView;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_query_alarm_result);
		
		
		
		//将当前界面加入到系统管理中国
		ActivityManagerAction.getScreenManager().pushActivity(this);
		iniView();
		dataMake();
		
		
	}

	private void dataMake() {
		
		String result = this.getIntent().getExtras().getString("data");
		
		 List<Map<String, Object>> listMap = JSON.parseObject(result, new TypeReference<List<Map<String,Object>>>(){}); 
		 
		 List<HistoryAlarmBean> beans = new ArrayList<HistoryAlarmBean>();
		 
		 for(Object obj:listMap){
			 
			 HistoryAlarmBean bean = new HistoryAlarmBean();
			 Map<String, Object> data =(Map<String, Object>) obj;
			 
			 bean.setValue(data.get("remake").toString());
			
			 SimpleDateFormat formate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			 bean.setTime( formate.format((data.get("time"))));
			 bean.setState(true);
			 beans.add(bean);
		 }
		 
		JSONArray.parse(result);
		
		
		HistoryAlarmItemAdapter adapter = new HistoryAlarmItemAdapter(this, beans);
		historyAlarmListView.setAdapter(adapter);
		
		Toast.makeText(QueryAlarmResultActivity.this, result, 1).show();
		
	}

	private void iniView() {
		left_img = (ImageView) findViewById(R.id.left_img);
		left_img.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
//				Intent intent = new Intent(UpdataUserPwdActivity.this,SettingActivity.class);
//				startActivity(intent);
				QueryAlarmResultActivity.this.finish();
			}
		});
		
		
		historyAlarmListView = (ListView) findViewById(R.id.historyAlarmListView);
		
		
		
	}
}
